﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/6/6 星期四 23:37:46
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Sector7.Medical.EntityType;
using Sector7.Framework.DB;
using Sector7.Medical.Consts;
using Sector7.Medical.DAO.Utility;

namespace Sector7.Medical.DAO.Standard
{
    /// <summary>
    /// <!-- The description about this class. -->
    /// </summary>
    public class SickAreaDAO : DAOBase<M7_SickArea>, ISickAreaDAO
    {
        #region Public functions

        /// <summary>
        /// 获取所有病区信息
        /// </summary>
        /// <returns></returns>
        public List<M7_SickArea> ReadAll()
        {
            string sql = @"
                SELECT *
                    FROM M7_SickArea
                    WHERE 1 = 1";

            using (DBHelper helper = new DBHelper())
            {
                List<M7_SickArea> areaList = new List<M7_SickArea>();

                SqlDataReader reader = helper.ExecuteQuery(sql);
                while (reader.Read())
                {
                    var area = new M7_SickArea();
                    DBUtil.ReadData(reader, area);

                    areaList.Add(area);
                }

                return areaList;
            }
        }

        /// <summary>
        /// 添加科室
        /// </summary>
        /// <param name="area">病区信息</param>
        /// <returns></returns>
        public override object Create(M7_SickArea area)
        {
            string sql = @"
                INSERT INTO M7_SickArea
                        (AreaName
                        ,SpellCode
                        ,IsValid
                        ,Remarks)
                    VALUES
                        (@AreaName
                        ,@SpellCode
                        ,@IsValid
                        ,@Remarks)
                SELECT @@IDENTITY";

            using (DBHelper helper = new DBHelper())
            {
                return helper.ExecuteScalar(sql,
                    DBUtil.CreateSqlParameter(area.AreaName, "AreaName"),
                    DBUtil.CreateSqlParameter(area.SpellCode, "SpellCode"),
                    DBUtil.CreateSqlParameter(area.IsValid, "IsValid"),
                    DBUtil.CreateSqlParameter(area.Remarks, "Remarks"));
            }
        }
        #endregion

        #region Structure
        public SickAreaDAO()
        {
            m_tableName = C_M7_TableName.SICK_AREA;
            m_primaryKeyName = C_ColumnName.AREA_ID;
        }
        #endregion
    }
}
